{% extends 'stocks/base.html' %}

{% block title %}{{ title }}{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row mb-4">
        <div class="col-12">
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="{% url 'home' %}">首页</a></li>
                    <li class="breadcrumb-item"><a href="{% url 'stock_detail' stock.symbol %}">{{ stock.symbol }} - {{ stock.name }}</a></li>
                    <li class="breadcrumb-item active">策略分析结果</li>
                </ol>
            </nav>
            <h2>{{ stock.symbol }} - {{ stock.name }} 策略分析结果</h2>
            {% if message %}
                <div class="alert alert-info">
                    <i class="fas fa-info-circle"></i> {{ message }}
                </div>
            {% endif %}
        </div>
    </div>

    {% if signals %}
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0">发现的买入信号</h5>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-striped table-hover">
                            <thead>
                                <tr>
                                    <th>策略名称</th>
                                    <th>信号日期</th>
                                    <th>信号价格</th>
                                    <th>信号强度</th>
                                    <th>买入理由</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for signal in signals %}
                                <tr>
                                    <td>{{ signal.strategy_name }}</td>
                                    <td>{{ signal.signal_date|date:"Y-m-d" }}</td>
                                    <td>¥{{ signal.signal_price|floatformat:2 }}</td>
                                    <td>
                                        <span class="badge {% if signal.signal_strength >= 80 %}bg-danger{% elif signal.signal_strength >= 60 %}bg-warning{% else %}bg-info{% endif %}">
                                            {{ signal.signal_strength|floatformat:1 }}
                                        </span>
                                    </td>
                                    <td>{{ signal.reason }}</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {% else %}
    <div class="row">
        <div class="col-12">
            <div class="alert alert-warning">
                <i class="fas fa-exclamation-triangle"></i> 未发现任何买入信号。
            </div>
        </div>
    </div>
    {% endif %}

    <div class="row mt-4">
        <div class="col-12">
            <div class="d-flex gap-2">
                <a href="{% url 'stock_detail' stock.symbol %}" class="btn btn-secondary">
                    <i class="fas fa-arrow-left"></i> 返回股票详情
                </a>
                <a href="{% url 'analyze_stock' stock.symbol %}" class="btn btn-primary">
                    <i class="fas fa-redo"></i> 重新分析
                </a>
                <a href="{% url 'buy_signals' %}" class="btn btn-outline-primary">
                    <i class="fas fa-search"></i> 查看所有信号
                </a>
            </div>
        </div>
    </div>
</div>
{% endblock %}
